/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package clientsimulator;

/**
 *
 * @author ab61930
 */
import java.io.*;
import java.net.*;
class UDPClient {
    private DatagramSocket clientSocket;
    private int port;
    private InetAddress IpAddress;
    public UDPClient(String ip, String p)
    {
        try
        {
            clientSocket = new DatagramSocket(35001);
            IpAddress = InetAddress.getByName(ip);
            port = Integer.parseInt(p.trim());
        }
        catch(Exception obj)
        {
            System.out.print(obj);
        }
    }

    public void sendToServer(byte[] data)
    {
        DatagramPacket sendPacket = new DatagramPacket(data, data.length, IpAddress, port);
	try
        {
            clientSocket.send(sendPacket);
        }
        catch(Exception obj)
        {
            System.out.print(obj);
        }
    }

    public DatagramSocket getSocket()
    {
        return clientSocket;
    }
	/*public static void main(String args[]) throws Exception
	{
		BufferedReader inFromUser=
			new BufferedReader(new InputStreamReader
				(System.in));
			DatagramSocket clientSocket = new DatagramSocket();
			InetAddress IPAddress =
					InetAddress.getByName("localhost");
				byte[] sendData = new byte[1024];
				byte[] receiveData = new byte[1024];
				String sentence = inFromUser.readLine();
				sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
				clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);					clientSocket.receive(receivePacket);
					String modifiedSentence =
					new String(receivePacket.getData());
					System.out.println("FROM SERVER:" + modifiedSentence);
					clientSocket.close();
	}*/
}
